Socket
Socket
Sign inDemoInstall

regexparam

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexparam

A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍


Version published
Weekly downloads
546K
increased by8.07%
Maintainers
1
Weekly downloads
 
Created

What is regexparam?

The regexparam npm package is a utility for matching URL patterns using regular expressions. It is designed to be lightweight and efficient, making it suitable for routing in web applications.

What are regexparam's main functionalities?

Basic Pattern Matching

This feature allows you to define URL patterns with named parameters. The `parse` function converts the pattern into a regular expression and extracts parameter names.

const { parse } = require('regexparam');
const result = parse('/user/:id');
console.log(result);

Matching URLs

This feature allows you to match a URL against a predefined pattern. The `match` function returns an object with the matched parameters if the URL matches the pattern.

const { match } = require('regexparam');
const pattern = parse('/user/:id');
const result = match('/user/123', pattern);
console.log(result);

Optional Parameters

This feature allows you to define optional parameters in your URL patterns. The `parse` function can handle patterns with optional parameters, and the `match` function will correctly match URLs with or without the optional parameter.

const { parse, match } = require('regexparam');
const pattern = parse('/user/:id?');
const result1 = match('/user/123', pattern);
const result2 = match('/user', pattern);
console.log(result1, result2);

Other packages similar to regexparam

Keywords

FAQs

Package last updated on 03 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc